<?php

$page_security = 'SA_SALESTRANSVIEW';
$path_to_root = "..";

include_once ($path_to_root . "/sales/includes/cart_class.inc");
include_once ($path_to_root . "/includes/session.inc");
include_once ($path_to_root . "/includes/date_functions.inc");
include_once ($path_to_root . "/sales/includes/sales_ui.inc");
include_once ($path_to_root . "/sales/includes/sales_db.inc");
include_once ($path_to_root . "/includes/db_pager.inc");
include_once ($path_to_root . "/includes/session.inc");
include_once ($path_to_root . "/reporting/includes/reporting.inc");

page(_($help_context = "Detil Pesanan"));
simple_page_mode(false);
start_form();
//create_cart(ST_SALESORDER, 9);
if (isset($_GET['order_no']))
    $order_no = $_GET['order_no'];

if (isset($_POST['order_no']))
    $order_no = $_POST['order_no'];

if (!isset($order_no))
{
    display_error("This page can't access directly!");
    exit();
}


//var_dump($order_no);
if ($Mode == 'UPDATE_ITEM')
{
    $isNew = $_POST['isNew'];
    $input_error = 0;

    if ($input_error != 1)
    {
        $row = array(
            'jns_brg' => $_POST['jns_brg'],
            'color' => $_POST['color'],
            'kombinasi' => $_POST['kombinasi'],
            'size_s' => $_POST['size_s'],
            'size_m' => $_POST['size_m'],
            'size_l' => $_POST['size_l'],
            'size_ml' => $_POST['size_ml'],
            'size_xxl' => $_POST['size_xxl'],
            'sablon' => $_POST['sablon'],
            'model_jahit' => $_POST['model_jahit'],
            'memo' => $_POST['memo'],
            );

        save_sales_order_item_details($selected_id, $row);

        display_notification(_('Selected detil item data have been saved'));

        $Mode = 'RESET';
    }
}
//var_dump($Mode);
$result = get_sales_order_details($order_no, '30');
$result_header = get_sales_order_header($order_no, '30');

//var_dump($result_header);
start_table(TABLESTYLE, "width=65%", 5);

echo "<tr><td>";
start_table(TABLESTYLE);
label_row(_("Customer Name"), $result_header['name'], "", null);
label_row(_("Customer Order Ref."), $result_header['reference'], "");
end_table();
echo "</td><td>";
start_table(TABLESTYLE);
label_row(_("Order Date"), $result_header['ord_date'], "");
label_row(_("Due Date"), $result_header['delivery_date'], "");
end_table();
echo "</td></tr>";


end_table();

br();
if ($Mode == 'RESET')
{
    $selected_id = -1;
    $sav = get_post('show_inactive');
    unset($_POST);
    $_POST['show_inactive'] = $sav;
}

start_table(TABLESTYLE, "width=65%", 5);
$th = array(
    _("Reference"),
    _("Description"),
    _("Quantity"),
    'Edit',
    'Produksi');
//inactive_control_column($th);
table_header($th);

$k = 0;

while ($myrow = db_fetch($result))
{
    alt_table_row_color($k);
    label_cell($myrow["ref"]);
    label_cell($myrow["description"]);
    label_cell($myrow["quantity"]);
    edit_button_cell("Edit" . $myrow["ref"], _("Edit"));
    hyperlink_params_td($path_to_root . '/manufacturing/work_order_entry.php',
        'Entri', 'soid_ref=' . $myrow["ref"]);
    end_row();
} //END WHILE LIST LOOP

//inactive_control_row($th);
end_table();
//var_dump($selected_id);
br();
if ($selected_id != -1)
{
    if ($Mode == 'Edit')
    {
        //editing an existing Sales-person
        $myrow = get_sales_order_item_details($selected_id);

        $_POST['jns_brg'] = $myrow["jns_brg"];
        $_POST['color'] = $myrow["color"];
        $_POST['kombinasi'] = $myrow["kombinasi"];
        $_POST['size_s'] = $myrow["size_s"];
        $_POST['size_m'] = $myrow["size_m"];
        $_POST['size_l'] = $myrow["size_l"];
        $_POST['size_ml'] = $myrow["size_ml"];
        $_POST['size_xxl'] = $myrow["size_xxl"];
        $_POST['sablon'] = $myrow["sablon"];
        $_POST['model_jahit'] = $myrow["model_jahit"];
        $_POST['memo'] = $myrow["memo"];
        //$_POST['order_no'] = $_POST['order_no'];
    }
    hidden('selected_id', $selected_id);
    hidden('isNew', $myrow == null);
}

hidden('order_no', $order_no);

start_table(TABLESTYLE, "width=65%", 5);

echo "<tr align='center'><td>";
echo "SPESIFIKASI";
echo "</td><td>";
echo "Spesifikasi/Model";
echo "</td></tr>";
echo "<tr><td>";
start_table(TABLESTYLE);
text_row_ex(_("Jenis Barang:"), 'jns_brg', 30);
text_row_ex(_("Warna:"), 'color', 30);
text_row_ex(_("Kombinasi:"), 'kombinasi', 30);
text_row_ex(_("Size S:"), 'size_s', 30);
text_row_ex(_("Size M:"), 'size_m', 30);
text_row_ex(_("Size L:"), 'size_l', 30);
text_row_ex(_("Size XL:"), 'size_ml', 30);
text_row_ex(_("Size XXL:"), 'size_xxl', 30);
text_row_ex(_("Sablon:"), 'sablon', 30);
text_row_ex(_("Model Jahit:"), 'model_jahit', 30);
end_table();
echo "</td><td>";
start_table(TABLESTYLE);
textarea_cells(null, 'memo', null, 100, 20);
//textarea_row(null, 'memo', null, 100, 20);
end_table();
echo "</td></tr
	>";
end_table();
br();
submit_add_or_update_center(false, '', 'both');
end_form();
end_page();

?>